//
//  HeadView.m
//  LotteryProject
//
//  Created by yhj on 2017/7/11.
//  Copyright © 2017年 阳光. All rights reserved.
//

#import "HeadView.h"

@interface HeadView ()

@property(nonatomic,strong)UIImageView *arrowIcon;

@property(nonatomic,strong)UIButton *nextBtn;

@property(nonatomic,strong)UIView *lineView;

@end

@implementation HeadView

-(instancetype)initWithTitle:(NSString *)title hasNext:(BOOL)next
{
    if (self=[super init]) {
        self.leftTitle=title;
        self.leftTitleLabel.textColor=DarkGreyColor;
        if (next)
        {
            self.arrowBtn.hidden=NO;
            self.arrowIcon.hidden=NO;
        }
        self.lineView.hidden=NO;
        self.backgroundColor=WhiteColor;
    }
    return self;
}

// 预防
- (instancetype)init {
    if (self = [super init]) {
        NSAssert1(NO, @"%s  必须使用initWithTitle:方法初始化", __FUNCTION__);
    }
    return self;
}

- (UILabel *)leftTitleLabel
{
    if (!_leftTitleLabel) {
        _leftTitleLabel=[UILabel new];
        [self addSubview:_leftTitleLabel];
        [_leftTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin*2);
            make.width.mas_equalTo(APPW/3);
            make.centerY.mas_equalTo(0);
        }];
        _leftTitleLabel.font=FontNumber(18);
        _leftTitleLabel.text=_leftTitle;
    }
    return _leftTitleLabel;
}


// arrowIcon
-(UIImageView *)arrowIcon
{
    if (!_arrowIcon) {
        _arrowIcon=[UIImageView new];
        [self addSubview:_arrowIcon];
        _arrowIcon.image=[UIImage imageNamed:@"next_arrow"];
        [_arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin*2);
            make.centerY.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(kmargin*3/2,kmargin*2));
        }];
    }
    return _arrowIcon;
}

-(UIButton *)nextBtn
{
    if (!_nextBtn) {
        _nextBtn=[UIButton new];
        [self addSubview:_nextBtn];
        [_nextBtn addTarget:self action:@selector(nextBtnEvent) forControlEvents:UIControlEventTouchUpInside];
        [_nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(0);
        }];
    }
    return _nextBtn;
}

-(UIView *)lineView
{
    if (!_lineView) {
        _lineView=[UIView new];
        _lineView.backgroundColor=LightGreyColor;
        [self addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(APPW,1));
            make.bottom.mas_equalTo(0);
        }];
    }
    return _lineView;
}
-(void)nextBtnEvent
{
    if (self.delegate &&[self.delegate respondsToSelector:@selector(nextBtnEvent)])
    {
        [self.delegate nextBtnEvent];
    }
}

@end
